package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) {
        try {
//            UserInfo userInfo =InputUtil.getInputObject(new UserInfo());
//            System.out.println(userInfo);
            Scanner scanner = new Scanner(System.in);
            Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement();
            String username,password,nickname;
            int age;
            System.out.println("请输入用户名");
            username = scanner.nextLine();
            System.out.println("请输入密码");
            password = scanner.nextLine();
            System.out.println("请输入昵称");
            nickname = scanner.nextLine();
            System.out.println("请输入年龄");
            age =Integer.parseInt(scanner.nextLine());
            String sql = "INSERT INTO userinfo (" +
                    "username,password,nickname,age)" +
                    "VALUES ('"+username+"','"+password+"','"+nickname+"',"+age+")";
            statement.executeUpdate(sql);
            scanner.close();
            connection.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
